<%--
  User: ssl
  Date: 2018-4-2
  Time: 15:40
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/commons/taglibs.jsp" %>
<html>
<head>
    <title>RMS管理系统</title>
    <!-- 导入公用css -->
    <%@ include file="/WEB-INF/views/commons/headcss.jsp" %>
    <!-- 导入公用js -->
    <%@ include file="/WEB-INF/views/commons/headjs.jsp" %>
    <!-- fancyTree -->
    <link href="${ctx}/resources/plugins/fancyTree/skin-bootstrap/ui.fancytree.css" rel="stylesheet">
    <script src="${ctx}/resources/plugins/fancyTree/jquery-ui-1.10.4.min.js"></script>
    <script src="${ctx}/resources/plugins/fancyTree/jquery.fancytree-all.min.js"></script>

</head>
<!-- 设置currentHref -->
<c:set var="currentHref" value="/sys/menu"></c:set>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow: hidden">
<div id="wrapper">
    <!--左侧导航开始-->
    <%@ include file="/WEB-INF/views/commons/menu.jsp" %>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            <!-- 页面头部 -->
            <%@ include file="/WEB-INF/views/commons/header.jsp" %>
        </div>
        <div class="row J_mainContent" id="content-main" style="overflow: auto">
            <div class="wrapper wrapper-content animated fadeInRight">
                <!-- 此处填充页面内容 -->
                <div class="row">
                    <div class="col-sm-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>节点列表
                                    <small>双击进行展开可查看子节点</small>
                                </h5>
                            </div>
                            <div class="ibox-content">
                                <div id="treeview">
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--  节点详细信息 -->
                    <div class="col-sm-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>节点详细信息
                                    <small>选中左侧节点进行查看</small>
                                </h5>
                            </div>
                            <div class="ibox-content">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="form-group">
                                            <label>父级菜单</label>
                                            <input type="text" id="parentId" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>名称</label>
                                            <input type="text" id="name" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>类型</label>
                                            <input type="text" id="type" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>链接</label>
                                            <input type="text" id="href" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>图标</label>
                                            <input type="text" id="icon" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>权限标识</label>
                                            <input type="text" id="permission" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>排序</label>
                                            <input type="text" id="sort" disabled="disabled" placeholder=""
                                                   class="form-control">
                                        </div>
                                        <button class="btn btn-primary btn-lg" data-toggle="modal"
                                                onclick="openCreateModel()">添加资源
                                        </button>
                                        <button class="btn btn-primary btn-lg" data-toggle="modal"
                                                onclick="openUpdateModel()">修改资源
                                        </button>
                                        <button class="btn btn-primary btn-lg" data-toggle="modal"
                                                onclick="deleted()">删除资源
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 节点详细信息end -->
                </div>
            </div>
        </div>
    </div>
    <!--右侧部分结束-->
</div>
<!-- create model -->
<div class="modal fade" id="createModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>
<!-- create model end -->
<!-- update model -->
<div class="modal fade" id="updateModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>
<!-- update model end -->
<!-- 加载全局js -->
<%@ include file="/WEB-INF/views/commons/foot.jsp" %>
</body>
<script>
    var currentSelectId = "";
    var currentSelectName = "";
    $(function () {
        var getTreeUrl = "";
        $("#treeview").fancytree({
            checkbox: true,
            selectMode: 2,
            source: {
                url: "${ctx}/sys/menu/findAll",
                cache: false
            },
            postProcess: function (event, data) {
                var dataResult = data.response;
                if (dataResult.code == "1") {
                    data.result = dataResult.data;
                } else {
                    data.result = {
                        error: "ERROR #:" + dataResult.msg
                    }
                }
            },
            activate: function (event, data) {
                //选中时候触发
                var node = data.node;
                currentSelectId = node.key;
                currentSelectName = node.title;
                var url = "${ctx}/sys/menu/get/" + node.key;
                var result = rmsAjax(url, "", "POST", "");
                if (!!result) {
                    if ("1" == result.code) {
                        //右侧显示详情
                        setMenuDetail(result.data);
                    } else {
                        notify("错误", result.msg, "error");
                    }
                }
            }
        });
    })
    //填充值
    function setMenuDetail(data) {
        if (!!data) {
            if (!!data.parentId) {
                var url = "${ctx}/sys/menu/get/" + data.parentId;
                var result = rmsAjax(url, "", "POST", "");
                if (!!result && "1" == result.code) {
                    $("#parentId").val(result.data.name);
                }
            } else {
                $("#parentId").val("");
            }
            $("#name").val(data.name);
            $("#type").val(data.type);
            $("#href").val(data.href);
            $("#icon").val(data.icon);
            $("#permission").val(data.permission);
            $("#sort").val(data.sort);
        }
    }
    // create
    function openCreateModel() {
        $('#createModel').modal({
            remote: "${ctx}/sys/menu/create?id=" + currentSelectId + "&name=" + currentSelectName
    })
        ;
    }
    // detail
    function openDetailModel() {
        $('#detailModel').modal({
            remote: "${ctx}/sys/menu/detail"
        });
    }
    // update
    function openUpdateModel() {
        if (!currentSelectId){
            notify("错误", "请先选择要修改的资源", "error");
            return;
        }
        $('#updateModel').modal({
            remote: "${ctx}/sys/menu/update/"+currentSelectId
        });
    }
    // deleted
    function deleted() {
        if (!currentSelectId){
            notify("错误", "请先选择要删除的资源", "error");
            return;
        }
        var url = "${ctx}/sys/menu/delete/"+currentSelectId;
        var result = rmsAjax(url, false, "POST", "");
        if (!!result) {
            if ("1" == result.code) {
                notify("成功", "删除成功", "success");
                window.location.href = "${ctx}/sys/menu";
            } else {
                notify("错误", result.msg, "error");
            }
        } else {
            return;
        }
    }
</script>
</html>

